﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ecopsy.DataTier;
using AgencyEntityLib.Context ;
using Ecopsy.DataTier.SqlLibrary;

namespace AgencyEntityLib.BaseEntity
{
    public class Client : Face_U 
    {
        [EntityNonSerialized]
        protected  override string TagName
        {
            get
            {
                return "Client";
            }
        }

        [EntityNonSerialized]
        public string FullName 
        {
            get { return Name; }
        }

        private string _CuratorID = string.Empty;
        public   string CuratorID
        {
            get
            {
                return _CuratorID ;
            }
            set { _CuratorID = value; }
        }

        private TreeDictionaryItemValue _Ctegoria=null ;
        public TreeDictionaryItemValue Ctegoria
        {
            get { return _Ctegoria;}
            set {_Ctegoria =value ;}
        }

        private TreeDictionaryItemValue _StatusValue = null;
        public TreeDictionaryItemValue StatusValue
        {
            get { return _StatusValue; }
            set { _StatusValue = value; }
        }

        [EntityNonSerialized]                                
        public string URL 
        {
            get { return GetContactValue(AgencyLib_GlobalConstants.Contact_Url); }
            set { SetContactValue(AgencyLib_GlobalConstants.Contact_Url, value); } 
        }

        private void SetContactValue(string ContactType, string ContactValue )
        {
            this.ContactList.RemoveItems(ContactType);
            this.ContactList.Add(new Contact { MainContact = true, ContactType = ContactType, ContactValue=ContactValue});            
        }

        private string GetContactValue (string ContactType)
        {
            Contact c = ContactList.GetMainContact(ContactType);
            if (c==null) return string.Empty;
            return c.ContactValue;
        }
        
        [EntityNonSerialized]                
        public string Phones 
        { 
            get 
            {
                return GetContactValue(AgencyLib_GlobalConstants.Contact_Phone);
                   
            } 
            set 
            {
                SetContactValue(AgencyLib_GlobalConstants.Contact_Phone, value);
            }
        }

        [EntityNonSerialized]
        public string Email
        {
            get
            {
                return GetContactValue(AgencyLib_GlobalConstants.Contact_Email);

            }
            set
            {
                SetContactValue(AgencyLib_GlobalConstants.Contact_Email, value);
            }
        }

        [EntityNonSerialized]
        public string Adress
        {
            get
            {
                return GetContactValue(AgencyLib_GlobalConstants.Contact_Adress);

            }
            set
            {
                SetContactValue(AgencyLib_GlobalConstants.Contact_Adress, value);
            }
        }
                
        public override void Save()
        {            
            base.Save();
        }

        public  ContactFaceList GetContactFaces()
        {
            wsFace ws = (wsFace)AgencyLib_GlobalConstants.CurrentAgency.WS_FactoryList[WS_FactoryList.wsKey_Face];
            ContactFaceList.sqlLoadStatment where = new ContactFaceList.sqlLoadStatment();
            vPropertyOfList.ParamListItem F = new vPropertyOfList.ParamListItem() { Param = "ClientID", Value = this.ID };
            where.ParamValueList.Add(F);
            where.ParamValueList_SearchOption = Ecopsy.DataTier.SqlLibrary.vPropertyOfList.Options.ParamValue;
            ContactFaceList l = ws.GetContactFaceList(where);
            return l;
        }

        public  TaskList GetTasks()
        {
            wsTask w = (wsTask)AgencyLib_GlobalConstants.CurrentAgency.WS_FactoryList[WS_FactoryList.wsKey_Task];
            TaskList.sqlLoadStatment where = new TaskList.sqlLoadStatment();
            where.Lexeme = this.ID;
            TaskList l = w.GetTaskList(where);
            return l;
        }
       

        public Employeer GetCurator()
        {
            try
            {
                if (string.Empty == this.CuratorID) return null;
                wsFace ws = (wsFace)AgencyLib_GlobalConstants.CurrentAgency.WS_FactoryList[WS_FactoryList.wsKey_Face];
                return ws.GetEmpl(this.CuratorID);
            }
            catch
            {
                return null;
            }

        }        

    }
    }
 

